// pages/list/list.js
const fetch = require('../../utils/fetch.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    activeIndex: 0,
    toView: 'a0',
    loading: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showLoading({
      title: '努力加载中'
    });
    fetch('food/list').then(res => {
      wx.hideLoading()
      this.setData({
        listData: res.data,
        loading: true
      })
    })
  },
  addToCart: function (e) {

  },
  selectMenu: function (e) {
    let index = e.currentTarget.dataset.index
    this.setData({
      activeIndex: index,
      toView: 'a' + index
    })
  },
  showCartList: function (e) {
    let type = e.currentTarget.dataset.type
    let index = e.currentTarget.dataset.index
    this.setData({
      currentType:type,
      currentIndex:index
    })
    let a = this.data
    let addItem = {
      name:a.listData[a.currentType].foods[a.currentIndex].name,
      price:a.listData[a.currentType].foods[a.currentIndex].specfoods[0].price,
      number:1,
      sum:a.listData[a.currentType].foods[a.currentIndex].specfoods[0].price
    }
    let sumMonney = a.sumMonney + a.listData[a.currentType].foods[a.currentIndex].specfoods[0].price
    let carList = this.data.carList
    carList.push(addItem)
    this.setData({
      carList:carList,
      showModalStatus:false,
      sumMonney:sumMonney,
      cupNumber:a.cupNumber + 1
    })
  },
  goBalance: function (e) {

  },
  clearCartList: function (e) {

  },
  decNumber: function (e) {

  },
  addNumber: function (e) {

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})